package com.wandian.game
{
		import com.dgphoenix.model.*;
		import com.dgphoenix.params.*;
		import com.dgphoenix.utils.*;
		import flash.display.*;
		import flash.events.*;
		import flash.text.*;
		
		public class ChooseCoin extends EventDispatcher
		{
			private var mcCoins:MovieClip;
			public var pressHandler:Function;
			private var coinId:Number;
			private var mc:MovieClip;
			public static const EVENT_COIN_CLICKED:String = "onCoinClicked";
			
			public function ChooseCoin(param1:MovieClip)
			{
				this.mc = param1;
				return;
			}// end function
			
			public function getValue() : Number
			{
				return Const.COINS[coinId];
			}// end function
			
			public function enable() : void
			{
				mc.gotoAndStop("on");
				mc.btn.enabled = true;
				mc.btn.addEventListener(MouseEvent.CLICK, onPress);
				return;
			}// end function
			
			public function getNextValue() : Number
			{
				return (coinId + 1) >= Const.COINS.length ? (0) : ((coinId + 1));
			}// end function
			
			public function getCoinId() : Number
			{
				return coinId;
			}// end function
			
			public function getPrevValue() : Number
			{
				return (coinId - 1) < 0 ? ((Const.COINS.length - 1)) : ((coinId - 1));
			}// end function
			
			private function onPress(event:Event) : void
			{
				this.onCoinClicked();
				pressHandler();
				return;
			}// end function
			
			public function disable() : void
			{
				mc.gotoAndStop("off");
				mc.btn.enabled = false;
				mc.btn.removeEventListener(MouseEvent.CLICK, onPress);
				return;
			}// end function
			
			public function setValue(param1:Number) : void
			{
				if (Const.COINS[param1] != null)
				{
					coinId = param1;
					if (ParamsSpecification.isCreditsDisplay)
					{
						mc.mcCoins.mcText.tf.text = Tools.formatCurrency(Const.COINS[param1]);
					}
					else
					{
						mc.mcCoins.mcText.tf.htmlText = ParamsSpecification.formatCurrencyWithSign(Const.COINS[param1]);
					}
					modifyTextForCurrencyMode();
				}
				GameData.getInstance().selectedCoin = param1;
				return;
			}// end function
			
			private function modifyTextForCurrencyMode() : void
			{
				var _loc_1:TextField = null;
				var _loc_2:uint = 0;
				trace("[ChooseCoin] modifyTextForCurrencyMode");
				_loc_1 = TextField(mc.mcCoins.mcText.tf);
				_loc_2 = _loc_1.text.length;
				if (_loc_2 > 4)
				{
					mc.mcCoins.mcText.scaleX = 4 / _loc_2;
					mc.mcCoins.mcText.scaleY = 5 / _loc_2;
				}
				else
				{
					mc.mcCoins.mcText.scaleX = 1;
					mc.mcCoins.mcText.scaleY = 1;
				}
				return;
			}// end function
			
			private function onCoinClicked() : void
			{
				this.dispatchEvent(new Event(EVENT_COIN_CLICKED));
				return;
			}// end function
			
			public function nextValue() : void
			{
				setValue(getNextValue());
				return;
			}// end function
			
		}
	}
